package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.entity.wx.PassiveMessage;
import cn.gjculture.shopping.api.service.PassiveMessageService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/passiveMessage")
public class PassiveMessageController {

    @Autowired
    PassiveMessageService passiveMessageService;

    @PostMapping
    public Return save(String params) {
        Return ret = new Return();
        PassiveMessage message= JSONObject.parseObject(params,PassiveMessage.class);
        if(passiveMessageService.insert(message)>0){
            ret.getCommon().setRet(true);
        }
        return ret;

    }

    @GetMapping
    public Return<List<PassiveMessage>> query(PassiveMessage message, PageInfo pageInfo) {
        Return<List<PassiveMessage>> ret = new Return<>();
        List<PassiveMessage> passiveMessages = passiveMessageService.query(message);
        ret.setData(passiveMessages);
        return ret;
    }

    @GetMapping(value = "/{id}")
    public Return<PassiveMessage> gitActivity(@PathVariable(value = "id") String id) {
        Return<PassiveMessage> ret = new Return<>();
        PassiveMessage passiveMessage = passiveMessageService.queryById(id);
        ret.setData(passiveMessage);
        return ret;
    }



    @DeleteMapping(value = "/{id}")
    public Return delete(@PathVariable(value = "id") String id) {
        Return ret = new Return<>();
        if(passiveMessageService.delete(id,ret)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @PostMapping(value = "/setValid")
    public Return setValid(PassiveMessage message){
        Return ret=new Return();
        if(passiveMessageService.setValid(message)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


}
